/**
 * 分类添加
 * @param exports
 * @returns
 */
layui.define(['common','api','form','layer'],function(exports){
	var laytpl = layui.laytpl;
	var $ = layui.jquery;
	var form = layui.form();
	var layer = layui.layer;

	var api = layui.api;
	var common = layui.common;

	//监听提交
  	form.on('submit(formDemo)', function(data){
		api.addCategory(data.field,function(res){
			if(res.status == 200){
				layer.alert(res.msg, {
		          icon: 1,
		          end:function(){
		          	location.href = '/blog/back/category';
		          }
		    });
			} else {
				layer.msg(res.msg || res.code, {
				shift: 6
			});
			}
		});
		return false;
	});

	api.allType({},function(res){
		if(res.status == 200){
			laytpl($("#template").html()).render(res,function(html){
				$("#type-cnt").html(html);
				form.render();
			});
  		} else {
  			common.error(res);
  		}
  	});

	exports('category-add',{});
});